
const parameter = getApp().globalData.parameter
const domainName = getApp().globalData.domainName

    // 重新上传头像
const reupload=(that, e)=>{
  wx.chooseMedia({
    count: 1,
    mediaType: ['image'],
    sizeType: ['compressed'],
    success: res => {
      let tempFile = res.tempFiles[0]
      if(tempFile.size>500000){
        wx.showModal({
          content: '上传照片不可超过500KB',
          showCancel: false,
          title: '提示',
        })
        return
      }
      wx.showLoading({
        title: '上传中……',
      })
      wx.uploadFile({
        filePath: tempFile.tempFilePath,
        name: 'files',
        url: domainName + '/stuRegister_info_updateStuPhoto',
        formData: {
          jg_stu_id:that.data.stu_info.jg_stu_id,
        },
        header : {'content-type':'application/x-www-form-urlencoded'},
        success: res => {
          let data = JSON.parse(res.data)
          console.log('data',data)
          if(data.update_res){
            wx.hideLoading()
            wx.showToast({
              title: '更新完成',
            })

            that.setData({
              tempFilePath:tempFile.tempFilePath
            })

            // 更新上一页数据
            var pages = getCurrentPages()
            let page_1 = pages[pages.length-2]  // 上页
            if(page_1){
              let stu_list_1 = page_1.data.stu_list
              stu_list_1[that.page_index_1].photo = tempFile.tempFilePath
              page_1.setData({
                stu_list:stu_list_1,
              })
            }

          }else{
            wx.showToast({
              title: '更新失败',
              duration: 1500,
              icon: 'error',
            })
          }
        },
      })
    },
  })
}  


  


// 更新学员状态
const update_stu_status=(that,jg_stu_id,set_status)=>{
  wx.request({
    url: domainName + '/stuRegister_info_updateStuStatus',
    data: {
      jg_stu_id:jg_stu_id,
      set_status:set_status,
    },...parameter,
    success: res => {
      if(res.data.update_res){
        wx.showToast({
          title: '操作成功',
          duration: 1500,
          icon: 'success',
        })
        that.setData({
          stu_info:res.data.stu_info
        })
      }
    },
  })
}

const page_init=(that, jg_stu_id)=>{
  wx.showLoading()
  wx.request({
    url: domainName + '/stuRegister_info_init',
    data: {
      jg_stu_id:jg_stu_id,
    },...parameter,
    success: res => {
      wx.hideLoading()
      let stu_info = res.data.stu_info
      if(JSON.stringify(stu_info) == '{}'){
        wx.showModal({
          content: '该学员暂无信息',
          showCancel: false,
          title: '提醒',
          success: res => {
            wx.navigateBack()
          },
        })
        return
      }
      that.setData({
        stu_info:stu_info,
        set_status:'',
      })
    },
  })
}


  module.exports={
    reupload,
    update_stu_status,
    page_init,
  }